rm(list=ls())
library(ggplot2)
library(dplyr)
library(psy)
library(ggplot2)
library(stargazer)
library(factoextra)
library(polycor)
library(mediation)
library(psych)
library(GPArotation)
library(lavaan)
library(nFactors)
library(sjPlot)
library(sjmisc)
library(ggExtra)  
library(interplot)
library(gridExtra)
library(dotwhisker)


us <- read.csv("US Survey_clean.csv")
kr <- read.csv("Korea Survey_clean.csv")
ch <- read.csv("China Survey_clean.csv")

# Covariate balance ############################################################

us$female[us$gen==2] <- 1
us$female[us$gen==1 | us$gen==3] <- 0
table(factor(us$male))

kr$female[kr$male==1] <- 0
kr$female[kr$male==0] <- 1

ch$female[ch$male==1] <- 0
ch$female[ch$male==0] <- 1

## US
t.test(us$female[us$treat==0], us$female[us$treat==1])
t.test(us$age[us$treat==0], us$age[us$treat==1])
t.test(us$inc[us$treat==0], us$inc[us$treat==1])
t.test(us$college[us$treat==0], us$college[us$treat==1])
t.test(us$white[us$treat==0], us$white[us$treat==1])
t.test(us$ideo[us$treat==0], us$ideo[us$treat==1])
t.test(us$pid[us$treat==0], us$pid[us$treat==1])
t.test(us$attention[us$treat==0], us$attention[us$treat==1])

## Korea
summary(aov(female ~ treat, data=kr))
summary(aov(age ~ treat, data=kr))
summary(aov(college ~ treat, data=kr))
summary(aov(ideo ~ treat, data=kr))
summary(aov(pass ~ treat, data=kr))

## China
summary(aov(female ~ treat, data=ch))
summary(aov(han ~ treat, data=ch))
summary(aov(age ~ treat, data=ch))
summary(aov(college ~ treat, data=ch))
summary(aov(pass ~ treat, data=ch))

# Main figures (barplots) ############################################################

library(ggpubr)
library(rstatix)

## US ##########################################################################
## Figure 2
us$country <- 1

# How much confidence would people around the world have re: US miliary support for its allies?

bp <- ggbarplot(
  us, x = "country", y = "cre_allies", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="How much confidence would people \naround the world have on US military \nsupport for its allies?", y ="Not confident at all (0) - Very confident (100)") +
  theme(title = element_text(size =20), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("US survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

stat.test <- us %>%
  group_by(country) %>%
  t_test(cre_allies ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}{p.signif}", tip.length = 0.05, size=5, vjust=0, y.position = 90)

# How much confidence would South Koreans have on US military support for their country?

bp <- ggbarplot(
  us, x = "country", y = "cre_ko", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="How much confidence would \nSouth Koreans have on US military \nsupport for their country?", y ="Not confident at all (0) - Very confident (100)") +
  theme(title = element_text(size =20), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("US survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

stat.test <- us %>%
  group_by(country) %>%
  t_test(cre_ko ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}{p.signif}", tip.length = 0.05, size=5, vjust=0, y.position = 90)

# How much confidence would the Chinese have on US military support for South Korea?

bp <- ggbarplot(
  us, x = "country", y = "cre_chi", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="How much confidence would \nthe Chinese have on US military \nsupport for South Korea?", y ="Not confident at all (0) - Very confident (100)") +
  theme(title = element_text(size =20), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("US survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

stat.test <- us %>%
  group_by(country) %>%
  t_test(cre_chi ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}", tip.length = 0.05, size=5, vjust=0, y.position = 90)


# Do you agree that US is committed to defending democracy and human rights around the world?

bp <- ggbarplot(
  us, x = "country", y = "cre_demo", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="How much confidence would people \naround the world have on US support \nfor democracy and human rights?", y ="Not confident at all (0) - Very confident (100)") +
  theme(title = element_text(size =20), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("US survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

stat.test <- us %>%
  group_by(country) %>%
  t_test(cre_demo ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}{p.signif}", tip.length = 0.05, size=5, vjust=0, y.position = 90)


## Korea, China ################################################################
### Figure 4
kr$country <- 1
ch$country <- 2

df1 <- data.frame(kr$country, kr$cre_allies, kr$cre_ko, kr$cre_demo, kr$treat) %>% filter(kr$treat==0|kr$treat==1)
colnames(df1) <- c('country', 'cre_allies', 'cre_ko', 'cre_demo','treat')

df2 <- data.frame(ch$country, ch$cre_allies, ch$cre_ko, ch$cre_demo,ch$treat) %>% filter(ch$treat==0|ch$treat==1)
colnames(df2) <- c('country', 'cre_allies', 'cre_ko', 'cre_demo','treat')

df3 <- rbind(df1, df2)
df3$country <- factor(df3$country)

# Do you agree that US is committed to defending its allies?

bp <- ggbarplot(
  df3, x = "country", y = "cre_allies", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="Do you agree that US is commited \nto defending its allies?", y ="Strongly disagree (0) - Strongly agree (100)") +
  theme(title = element_text(size =23), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("Korea survey", "China survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

bp

stat.test <- df3 %>%
  group_by(country) %>%
  t_test(cre_allies ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}", tip.length = 0.05, size=5, vjust=0, y.position = 90)


# Do you agree that US is committed to defending its allies?

bp <- ggbarplot(
  df3, x = "country", y = "cre_ko", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="How confident are you that \nUS will defend South Korea?", y ="Not confident at all (0) - Very confident (100)") +
  theme(title = element_text(size =23), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("Korea survey", "China survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

bp

stat.test <- df3 %>%
  group_by(country) %>%
  t_test(cre_ko ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}", tip.length = 0.05, size=5, vjust=0, y.position = 90)

# Do you agree that US is committed to defending democracy and human rights around the world?

bp <- ggbarplot(
  df3, x = "country", y = "cre_demo", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="Do you agree that US is committed to \ndefending democracy and human rights \naround the world?", y ="Strongly disagree (0) - Strongly agree (100)") +
  theme(title = element_text(size =20), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("Korea survey", "China survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

bp

stat.test <- df3 %>%
  group_by(country) %>%
  t_test(cre_demo ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}", tip.length = 0.05, size=5, vjust=0, y.position = 90)

### Korea, China surveys: Resource prioritization treatment only #####################################

df1 <- data.frame(kr$country, kr$cre_allies, kr$cre_ko, kr$cre_demo, kr$treat) %>% filter(kr$treat==0|kr$treat==1)
colnames(df1) <- c('country', 'cre_allies', 'cre_ko', 'cre_demo','treat')

df2 <- data.frame(ch$country, ch$cre_allies, ch$cre_ko, ch$cre_demo,ch$treat) %>% filter(ch$treat==0|ch$treat==1)
colnames(df2) <- c('country', 'cre_allies', 'cre_ko', 'cre_demo','treat')

df3 <- rbind(df1, df2)
df3$country <- factor(df3$country)

# Do you agree that US is committed to defending its allies?

bp <- ggbarplot(
  df3, x = "country", y = "cre_allies", add = "mean_ci",
  fill= "treat", label=TRUE, lab.pos = "out", lab.size = 6, lab.nb.digits = 0,lab.vjust = -1.2, lab.col="black",
  position = position_dodge(0.75)) + ylim(0,100) +
  geom_hline(yintercept = 50, linetype = "dashed", color = "grey") +
  labs(title="Do you agree that US is commited \nto defending its allies?", y ="Strongly disagree (0) - Strongly agree (100)") +
  theme(title = element_text(size =23), legend.pos = "bottom",
        axis.title.x = element_text(size = 22),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(color="black", size=20, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        legend.title = element_blank(), 
        legend.text = element_text(size = 22)) + xlab("") +
  scale_x_discrete(labels=c("Korea survey", "China survey")) +
  scale_fill_grey(start=0.9, end=0.4,labels=c("Control", "Afghan condition"))

bp

stat.test <- df3 %>%
  group_by(country) %>%
  t_test(cre_allies ~ treat) %>%
  add_significance("p")

stat.test <- stat.test %>%
  add_xy_position(x = "country", dodge = 0.8)

bp + stat_pvalue_manual(
  stat.test,  label = "{p}", tip.length = 0.05, size=5, vjust=0, y.position = 90)


# Main figures (coefficient plots) ############################################################

us$treat <- factor(us$treat)
kr$treat <- factor(kr$treat)
ch$treat <- factor(ch$treat)

table(us$cre_allies)
table(ch$treat)

## US result - main question
summary(r0 <- lm(cre_allies ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r01 <- lm(cre_allies ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==0))
summary(r02 <- lm(cre_allies ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==1))

summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r2 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==0))
summary(r3 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==1))

summary(r4 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r5 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==0))
summary(r6 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us,subset=iso_high==1))

rp1 <- dwplot(list(r0), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 3", "Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How much confidence \n would people around the world have \n re: US military support for its allies?") +
  theme(title = element_text(size=15.5),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=16, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=17)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-8, 5))

rp2 <- dwplot(list(r1), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 3", "Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How much confidence \n would South Koreans have \n re: US military support for their country?") +
  theme(title = element_text(size=15.5),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=16, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=17)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-8, 5))

       

rp3 <- dwplot(list(r4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 3", "Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How much confidence \n would the Chinese have \n re: US military support for South Korea?") +
  theme(title = element_text(size=15.5),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=16, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=17)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2", "Model 3"), labels=c("US survey", "Low isolationism", "High isolationism")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-8, 5))

grid.arrange(rp1, rp2, rp3, ncol=3)

## Figure 3 (Subgroup analysis - US)

### Q: "How much confidence would South Koreans have...?"
### PID
summary(r1 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))
summary(r2 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))
summary(r3 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))


rp1 <- dwplot(list(r1, r2, r3), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 3","Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20),
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2", "Model 3"), labels=c("Democrat", "Independent", "Republican")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2", "Model 3"), labels=c("Democrat", "Independent", "Republican")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-13,5)) + 
  coord_flip() 

grid.arrange(rp1, ncol=1)

### Education

summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==0))
summary(r2 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==1))


rp2 <- dwplot(list(r1, r2), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20),
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-13,5)) + 
  coord_flip() 

grid.arrange(rp2, ncol=1)

### Isolationism
summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==0))
summary(r5 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==1))


rp3 <- dwplot(list(r1, r5), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Low isolationism", "High isolationism")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Low isolationism", "High isolationism")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-10,3)) + 
  coord_flip()

library(grid)
library(gridExtra)

grid.arrange(rp1, rp2, rp3, ncol=3, top = textGrob("How much confidence would South Koreans have on US military support for their country?",gp=gpar(fontsize=20,font=3)))


### Q: "How much confidence would Chinese have...?"
### PID
summary(r1 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))
summary(r2 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))
summary(r3 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))

rp1 <- dwplot(list(r1, r2, r3), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 3","Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20),
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2", "Model 3"), labels=c("Democrat", "Independent", "Republican")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2", "Model 3"), labels=c("Democrat", "Independent", "Republican")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-13,5)) + 
  coord_flip() 

grid.arrange(rp1, ncol=1)

### Education

summary(r1 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==0))
summary(r2 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==1))


rp2 <- dwplot(list(r1, r2), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20),
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-10,8)) + 
  coord_flip() 

grid.arrange(rp2, ncol=1)

### Isolationism
summary(r1 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==0))
summary(r5 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==1))


rp3 <- dwplot(list(r1, r5), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Low isolationism", "High isolationism")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Low isolationism", "High isolationism")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-8,5)) + 
  coord_flip()

library(grid)
library(gridExtra)

grid.arrange(rp1, rp2, rp3, ncol=3, top = textGrob("How much confidence would the Chinese have on US military support for South Korea?",gp=gpar(fontsize=20,font=3)))


## US vs. KR vs. CH - main question

kr$cre_allies <- kr$cre_allies*20
kr$cre_demo <- kr$cre_demo*20

ch$cre_allies <- dplyr::recode(ch$cre_allies, '1'=100, '4'=75,'5'=50,'6'=25,'7'=0)
ch$cre_demo <- dplyr::recode(ch$cre_demo, '1'=100, '4'=75,'5'=50,'6'=25,'7'=0)


summary(f2 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(f3 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch))

summary(q3 <- lm(cre_allies ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(q4 <- lm(cre_allies ~ treat + factor(male) + factor(han) + age + edu, data=ch))

qp1 <- dwplot(list(q3, q4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = " Prioritization \n condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" Do you agree that US is \n committed to defending allies?") +
  theme(title = element_text(size=20),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=22, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-9, 8))

qp2 <- dwplot(list(f2, f3), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = " Prioritization \n condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How confident are you that \n US will defend South Korea?") +
  theme(title = element_text(size=20),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=22, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-9, 8))

grid.arrange(qp1, qp2, ncol=2)


## US vs. KR vs. CH - supplementary question: democracy and human rights


summary(f4 <- lm(cre_demo ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(f5 <- lm(cre_demo ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(f6 <- lm(cre_demo ~ treat + factor(male) + factor(han) + age + edu, data=ch))

pf1 <- dwplot(list(f4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = " Prioritization \n condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How much confidence would people \n around the world have on US support \n for democracy and human rights?") +
  theme(title = element_text(size=20),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=22, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("US survey", "")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("US survey", "blank")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-7, 4))

pf2 <- dwplot(list(f5, f6), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat1"),
       model_order=c("Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = " Prioritization \n condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" Do you agree that US is committed to \n defending democracy and human rights \n around the world?") +
  theme(title = element_text(size=20),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=22, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() + xlim(c(-7, 4))

grid.arrange(pf1, pf2, ncol=2)

## Figure 5 (KR vs. CH - prioritization condition)

summary(z1 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(z2 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch))

dwplot(list(z1, z2), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
       vars_order=c("treat2"),
       model_order=c("Model 2", "Model 1"),
       dot_args = list(aes(shape = model), lwd=3),
       whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = " Prioritization \n condition")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("How confident are you that US will defend South Korea?") +
  theme(title = element_text(size=20),
        axis.title.x = element_text(size = 2), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=22, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="right",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + 
  coord_flip() 




## Subgroup analysis - Korea & China; Afghan condition

summary(f1 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==0))
summary(f2 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==1))

summary(f3 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==0))
summary(f4 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==1))

summary(f5 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==0))
summary(f6 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==1))

summary(f7 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==0))
summary(f8 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==1))

fp1 <- dwplot(list(f1, f2), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Korea survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-10,8)) + 
  coord_flip()

grid.arrange(fp1, ncol=1)

fp2 <- dwplot(list(f3, f4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Korea survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-8,8)) + 
  coord_flip()

grid.arrange(fp2, ncol=1)

fp3 <- dwplot(list(f5, f6), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("China survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-7,10)) + 
  coord_flip()

grid.arrange(fp3, ncol=1)

fp4 <- dwplot(list(f7, f8), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat1"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("China survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-5,10)) + 
  coord_flip()

grid.arrange(fp4, ncol=1)

grid.arrange(fp1, fp2, fp3, fp4, ncol=4, top = textGrob("How confident are you that US will defend South Korea? \n   ",gp=gpar(fontsize=20,font=3)))


## Figure 7 (Subgroup analysis - Korea & China; Prioritization condition)

summary(f1 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==0))
summary(f2 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==1))

summary(f3 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==0))
summary(f4 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==1))

summary(f5 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==0))
summary(f6 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==1))

summary(f7 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==0))
summary(f8 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==1))

fp1 <- dwplot(list(f1, f2), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Korea survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-5,12)) + 
  coord_flip()

grid.arrange(fp1, ncol=1)

fp2 <- dwplot(list(f3, f4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Korea survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-1,13)) + 
  coord_flip()

grid.arrange(fp2, ncol=1)

fp3 <- dwplot(list(f5, f6), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("China survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Below college", "College & above")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-3,15)) + 
  coord_flip()

grid.arrange(fp3, ncol=1)

fp4 <- dwplot(list(f7, f8), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle("China survey") +
  theme(title = element_text(size=13),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=18, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20), 
        legend.direction ="vertical") +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Dove", "Hawk")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-1,20)) + 
  coord_flip()

grid.arrange(fp4, ncol=1)

grid.arrange(fp1, fp2, fp3, fp4, ncol=4, top = textGrob("How confident are you that US will defend South Korea? \n   ",gp=gpar(fontsize=20,font=3)))


## Figure 6 (KR vs. CH - prioritization condition: long-term effects)

summary(o1 <- lm(cre_ko_fu1 ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(o2 <- lm(cre_ko_fu2 ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(o3 <- lm(cre_ko_fu3 ~ treat + ideo + factor(male) + age + edu, data=kr))

summary(o4 <- lm(cre_ko_fu1 ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(o5 <- lm(cre_ko_fu2 ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(o6 <- lm(cre_ko_fu3 ~ treat + factor(male) + factor(han) + age + edu, data=ch))

op1 <- dwplot(list(o1, o4), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How confident are you that \n US will defend South Korea \n in 10 years?") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-1,13)) + 
  coord_flip() 

op2 <- dwplot(list(o2, o5), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How confident are you that \n US will defend South Korea \n in 30 years?") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-1,13)) + 
  coord_flip() 

op3 <- dwplot(list(o3, o6), vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2), 
              vars_order=c("treat2"),
              model_order=c("Model 2", "Model 1"),
              dot_args = list(aes(shape = model), lwd=3),
              whisker_args = list(aes(linetype = model), lwd=0.7)) %>%
  relabel_predictors(c(treat1 = "Afghan condition", treat2 = "Prioritization \n condition ")) +
  theme_classic() + xlab("Coefficient Estimate") + ylab("") +
  ggtitle(" How confident are you that \n US will defend South Korea \n in 50 years?") +
  theme(title = element_text(size=18),
        axis.title.x = element_text(size = 16), 
        axis.title.y = element_text(size = 16),
        axis.text.y = element_text(color="black", size=18, angle=0),
        axis.text.x = element_text(color="black", size=20, angle=0),
        plot.title = element_text(face="bold"),
        legend.justification = c(0, 0), 
        legend.title = element_blank(),
        legend.position="bottom",legend.text=element_text(size=20)) +
  scale_colour_grey(start =.1, end= .1, name="Model", breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  scale_shape_discrete(name="Model",  breaks=c("Model 1", "Model 2"), labels=c("Korea survey", "China survey")) +
  guides(shape=guide_legend("Model"), colour=guide_legend("Model")) + xlim(c(-1,13)) + 
  coord_flip() 

grid.arrange(op1, op2, op3, ncol=3)

# Regression tables ############################################################

## Table A5 (US main)
summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r2 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r3 <- lm(cre_allies ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))
summary(r4 <- lm(cre_demo ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us))

stargazer(r1, r2, r3, r4,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001))

## Table A6 (US subgroup x PID)

summary(r1 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))
summary(r2 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))

summary(r3 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))
summary(r4 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))

summary(r5 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))
summary(r6 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))

stargazer(r1, r2, r3, r4,r5, r6,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.1, 0.05, 0.01, 0.001), star.char = c("+", "*", "**", "***"))

## Table A7 (US subgroup x Education, Isolationism)

summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==0))
summary(r2 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==0))
summary(r3 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==1))
summary(r4 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc, data=us, subset=college==1))

summary(r5 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==0))
summary(r6 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==0))
summary(r7 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==1))
summary(r8 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=iso_high==1))

stargazer(r1, r2, r3, r4,r5, r6, r7, r8,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.1, 0.05, 0.01, 0.001), star.char = c("+", "*", "**", "***"))

## Table A7 (US subgroup x Education)

summary(r1 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))
summary(r2 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==0))

summary(r3 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))
summary(r4 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==1))

summary(r5 <- lm(cre_ko ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))
summary(r6 <- lm(cre_chi ~ treat + ideo + factor(male) + factor(race2) + age + inc + edu, data=us, subset=pid2==2))

stargazer(r1, r2, r3, r4,r5, r6,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.1, 0.05, 0.01, 0.001), star.char = c("+", "*", "**", "***"))

## Table A8 (Korea main)

kr$nuke <- dplyr::recode(kr$Q9, '1'=100, '2'=75,'3'=50,'4'=25,'5'=0)

summary(r1 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r2 <- lm(cre_ko_fu1 ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r3 <- lm(cre_ko_fu2 ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r4 <- lm(cre_ko_fu3 ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r5 <- lm(cre_allies ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r6 <- lm(cre_demo ~ treat + ideo + factor(male) + age + edu, data=kr))
summary(r7 <- lm(nuke ~ treat + ideo + factor(male) + age + edu, data=kr))

stargazer(r1, r2, r3, r4,r5, r6,r7,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001), star.char = c("*", "**", "***"))

## Table A9 (China main)

summary(r1 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(r2 <- lm(cre_ko_fu1 ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(r3 <- lm(cre_ko_fu2 ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(r4 <- lm(cre_ko_fu3 ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(r5 <- lm(cre_allies ~ treat + factor(male) + factor(han) + age + edu, data=ch))
summary(r6 <- lm(cre_demo ~ treat + factor(male) + factor(han) + age + edu, data=ch))

stargazer(r1, r2, r3, r4,r5, r6,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001), star.char = c("*", "**", "***"))


### Main tables exluding those who didn't pass the manipulation check

prop.table(table(us$manipulation)) # about 40% failed

kr$manipulation <- 1
kr$manipulation[kr$Q4_1 ==0 | kr$Q4_2==0] <- 0
prop.table(table(kr$manipulation)) # less than 4%

ch$manipulation <- 1
ch$manipulation[ch$mani_afghan ==1 | ch$mani_afghan_prio==1] <- 0
prop.table(table(ch$manipulation)) # less than 1%


us_m <-  us %>% filter(us$manipulation == 1 | is.na(us$manipulation))
kr_m <- kr %>% filter(kr$manipulation==1)
ch_m <- ch %>% filter(ch$manipulation==1)

## Table A10 (US main - manipulation check)

summary(r1 <- lm(cre_ko ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us_m))
summary(r2 <- lm(cre_chi ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us_m))
summary(r3 <- lm(cre_allies ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us_m))
summary(r4 <- lm(cre_demo ~ treat + pid + ideo + factor(male) + factor(race2) + age + inc + edu, data=us_m))

stargazer(r1, r2, r3, r4,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001))

## Table A11 (Korea main - manipulation check)

summary(r1 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r2 <- lm(cre_ko_fu1 ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r3 <- lm(cre_ko_fu2 ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r4 <- lm(cre_ko_fu3 ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r5 <- lm(cre_allies ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r6 <- lm(cre_demo ~ treat + ideo + factor(male) + age + edu, data=kr_m))
summary(r7 <- lm(nuke ~ treat + ideo + factor(male) + age + edu, data=kr_m))

stargazer(r1, r2, r3, r4,r5, r6,r7,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001), star.char = c("*", "**", "***"))

## Table A12 (China main - manipulation check)

summary(r1 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))
summary(r2 <- lm(cre_ko_fu1 ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))
summary(r3 <- lm(cre_ko_fu2 ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))
summary(r4 <- lm(cre_ko_fu3 ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))
summary(r5 <- lm(cre_allies ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))
summary(r6 <- lm(cre_demo ~ treat + factor(male) + factor(han) + age + edu, data=ch_m))

stargazer(r1, r2, r3, r4,r5, r6,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001), star.char = c("*", "**", "***"))

## Table A13 (Korea survey - Subgroup analyses)

summary(f1 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==0))
summary(f2 <- lm(cre_ko ~ treat + ideo + factor(male) + age, data=kr, subset=college==1))

summary(f3 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==0))
summary(f4 <- lm(cre_ko ~ treat + ideo + factor(male) + age + edu, data=kr, subset=ma_high==1))

## Table A14 (China survey - Subgroup analyses)

summary(f5 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==0))
summary(f6 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age, data=ch, subset=college==1))

summary(f7 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==0))
summary(f8 <- lm(cre_ko ~ treat + factor(male) + factor(han) + age + edu, data=ch, subset=ma_high==1))

stargazer(f1, f2, f3, f4, f5, f6, f7, f8,
          title="",
          dep.var.labels =c(),
          keep.stat = c("n", "adj.rsq"), 
          digits=2, star.cutoffs = c(0.05, 0.01, 0.001), star.char = c("*", "**", "***"))
